#include <console.h>
#include <stdio.h>
#include <fcntl.h>
#include <prodos.h>
#include <sgtty.h>
#include <device.h>
#include <sysfunc.h>

/* globals to override the load point for the image loader  */
/* normally the loader centres partial images on the screen */

extern unsigned HB[];

char XPIC=0;
char YPIC=0;

piclode(name)
char *name;
{
   int fh,y,y1=0,x1,bos;
   char buffer[41];

   int height,packet;
   char tempchar[2];

   fh = open(name,O_RDONLY,0xc3); /* open a binary file */
                              
   read(fh,tempchar,2);

   packet= (int)tempchar[0];
   height= (int)tempchar[1];

   /* center the picture in the screen */
   if(XPIC>39)
      x1 = 20-(packet/2); /* break on even byte boundaries */
   else
      x1 = (int)XPIC;

   if((x1%2)!=0)x1--;

   if(YPIC>191)
      y1=96-(height/2);
   else
      y1=(int)YPIC;

   bos=y1+height;

   for(y=y1;y<bos;y++)
     read(fh,(char *)(HB[y]+x1),packet); /* read each raster to the screen */
   close(fh);

   /* zero our globals each time */
   XPIC=0;
   YPIC=0;

}
